
begin TRAN tran_banve_fix
SET	TRAN ISOLATION	LEVEL  READ	COMMITTED

	DECLARE @MaVe VARCHAR(10)
	DECLARE @NguoiLon BIT
	DECLARE @TongTien INT 
	SET @MaVe = 'V1'
	SET @NguoiLon = 1
	declare @giaNguoiLon int
	declare @giaTreEm int

	set @tongTien = 0

	select @giaNguoiLon = CTSUATCHIEU.GiaVeNguoiLon, @giaTreEm = CTSUATCHIEU.GiaVeTreEm 
	from CTSUATCHIEU join VE on CTSUATCHIEU.MaCTSuatChieu = VE.MaCTSuatChieu
	where VE.MaVe= @maVe

	--cap nhat ban ve
	update VE
	set ve.TinhTrangVe = 2, ve.NguoiLon_TreEm = @NguoiLon
	where VE.MaVe = @maVe

	--tinh tong tien can thu
	if(@NguoiLon = 1)
		set @tongTien = @giaNguoiLon
	else
		set @tongTien = @giaTreEm

	if(@@ERROR <>0)
	begin
		print @@error;
		rollback
	end
COMMIT TRAN tran_banve_fix
go
------------------------------------------------